<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>make_sheet (Table)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File ex.rb, line 26</span>
 <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">make_sheet</span> <span class="ruby-identifier">book</span>,<span class="ruby-identifier">name</span>,<span class="ruby-identifier">table</span>
  <span class="ruby-identifier">sheet1</span> = <span class="ruby-identifier">book</span>.<span class="ruby-identifier">create_worksheet</span>
  <span class="ruby-identifier">sheet1</span>.<span class="ruby-identifier">name</span> = <span class="ruby-identifier">name</span>

  <span class="ruby-identifier">table</span>.<span class="ruby-identifier">rows</span>.<span class="ruby-identifier">each_with_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">r</span>,<span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">r</span>[<span class="ruby-identifier">:cols</span>].<span class="ruby-identifier">each_with_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span>,<span class="ruby-identifier">col</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">sheet1</span>[<span class="ruby-identifier">row</span>,<span class="ruby-identifier">col</span>] = <span class="ruby-identifier">c</span>
    }
  }
  <span class="ruby-identifier">fmatted</span> = []
  <span class="ruby-identifier">table</span>.<span class="ruby-identifier">formats</span>.<span class="ruby-identifier">each_key</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">format</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">formats</span>[<span class="ruby-identifier">f</span>][<span class="ruby-value">2</span>]
    <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">fmatted</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">f</span>)
      <span class="ruby-identifier">sheet1</span>.<span class="ruby-identifier">row</span>(<span class="ruby-identifier">table</span>.<span class="ruby-identifier">formats</span>[<span class="ruby-identifier">f</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">to_i</span>).<span class="ruby-identifier">set_format</span>(<span class="ruby-identifier">table</span>.<span class="ruby-identifier">formats</span>[<span class="ruby-identifier">f</span>][<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>,<span class="ruby-identifier">format</span>)
    <span class="ruby-keyword kw">end</span>
    <span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span>  = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">formats</span>[<span class="ruby-identifier">f</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">to_i</span>,<span class="ruby-identifier">table</span>.<span class="ruby-identifier">formats</span>[<span class="ruby-identifier">f</span>][<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>
    <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">table</span>.<span class="ruby-identifier">also</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-node">&quot;#{x}:#{y}&quot;</span>)
     <span class="ruby-identifier">table</span>.<span class="ruby-identifier">also</span>[<span class="ruby-node">&quot;#{x}:#{y}&quot;</span>].<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">col</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">format</span> = <span class="ruby-identifier">table</span>.<span class="ruby-identifier">formats</span>[<span class="ruby-node">&quot;#{x}:#{col}&quot;</span>][<span class="ruby-value">2</span>]
      <span class="ruby-identifier">fmatted</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{x}:#{col}&quot;</span>
<span class="ruby-comment cmt"># p fmatted</span>
      <span class="ruby-identifier">sheet1</span>.<span class="ruby-identifier">row</span>(<span class="ruby-identifier">x</span>).<span class="ruby-identifier">set_format</span>(<span class="ruby-identifier">col</span>,<span class="ruby-identifier">format</span>)
     }
    <span class="ruby-keyword kw">end</span>
  }
  [<span class="ruby-identifier">book</span>,<span class="ruby-identifier">sheet1</span>]
 <span class="ruby-keyword kw">end</span></pre>
</body>
</html>